package org.lonetree.tc.core;

import java.util.HashSet;
import java.util.Set;
import org.lonetree.tc.core.Book.Isbn;
import org.lonetree.tc.core.Course.CourseId;
import org.lonetree.tc.core.User.EmailAddress;
import org.lonetree.tc.core.User.Username;
import org.lonetree.tc.core.dao.BookDAO;
import org.lonetree.tc.core.dao.CourseDAO;
import org.lonetree.tc.core.dao.UserDAO;
import org.lonetree.tc.core.exception.AttributeCannotBeNullException;
import org.lonetree.tc.core.exception.ItemAlreadyExistsException;
import org.lonetree.tc.core.exception.NoSuchItemException;
import org.lonetree.tc.core.exception.SearchException;
import org.lonetree.tc.core.id.ValidatedIdentifier.ValidationException;
import org.lonetree.tc.core.search.BookCriteria;
import org.lonetree.tc.core.search.CourseCriteria;
import org.lonetree.tc.core.search.UserCriteria;


public class StubDAOImpl implements UserDAO, BookDAO, CourseDAO{

	public Book createBook(Isbn isbn) throws ItemAlreadyExistsException{
		System.out.println("Book created: " + isbn);
		return new Book(isbn);
	}

	public Course createCourse(CourseId courseId) throws ItemAlreadyExistsException{
		System.out.println("Course created: " + courseId);
		return new Course(courseId);
	}

	public User createUser(Username username) throws ItemAlreadyExistsException{
		System.out.println("User created: " + username);
		return new User(username);
	}
	
	public Set<User> findUsers(UserCriteria criteria) throws SearchException{
		System.out.println("Users found using criteria: " + criteria);
		return new HashSet<User>();
	}

	public Set<Book> findBooks(BookCriteria criteria) throws SearchException{
		System.out.println("Books found using criteria: " + criteria);
		return new HashSet<Book>();
	}

	public Set<Course> findCourses(CourseCriteria criteria) throws SearchException{
		System.out.println("Courses found using criteria: " + criteria);
		return new HashSet<Course>();
	}

	public Book getBook(Isbn isbn) throws NoSuchItemException{
		System.out.println("Book retrieved: " + isbn);
		Set<String> auth = new HashSet<String>();
		auth.add("Author 1");
		auth.add("Author 2");
		return new Book(isbn, "Title", auth, null, null, null, false);
	}

	public Course getCourse(CourseId courseId) throws NoSuchItemException{
		System.out.println("Course retrieved: " + courseId);
		return new Course(courseId, "Title", null, null);
	}
	
	public User getUser(Username username) throws NoSuchItemException{
		try{
			System.out.println("User retrieved: " + username);
			return new User(username, "FirstName", "LastName", "pwd", new EmailAddress("FirstNameLastName@domain.com"), "location", null, null, false, false);
		}
		catch(ValidationException e){
			e.printStackTrace();
			return null;
		}
	}

	public void removeBook(Isbn isbn) throws NoSuchItemException{
		System.out.println("Book removed" + isbn);
	}

	public void removeCourse(CourseId courseId) throws NoSuchItemException{
		System.out.println("Course removed" + courseId);
	}

	public void removeUser(Username username) throws NoSuchItemException{
		System.out.println("User removed" + username);
	}

	public void updateBook(Book book) throws NoSuchItemException, AttributeCannotBeNullException{
		System.out.println("Book updated" + book);
	}

	public void updateCourse(Course course) throws NoSuchItemException, AttributeCannotBeNullException{
		System.out.println("Course updated" + course);
	}

	public void updateUser(User user) throws NoSuchItemException, AttributeCannotBeNullException{
		System.out.println("User updated" + user);
	}

	public Set<BookComment> getFlaggedBookComments(){
		return new HashSet<BookComment>();
	}

	public Set<CourseComment> getFlaggedCourseComments(){
		return new HashSet<CourseComment>();
	}
}
